<!DOCTYPE HTML>
<html>
<head>
    <title>商品列表</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- jquery -->
    <link type="text/javascript" href="/js/jquery.min.js"/>
    <!-- bootstrap -->
    <link rel="stylesheet" type=" text/css" href="/bootstrap/css/bootstrap.min.css" />
    <link type="text/javascript" href="/bootstrap/js/bootstrap.min.js"/>
    <!-- jquery-validator -->
    <link type="text/javascript" href="/jquery-validation/jquery.validate.min.js"/>
    <link type="text/javascript" href="/jquery-validation/localization/messages_zh.min.js"/>
    <!-- layer -->
    <link type="text/javascript" href="/layer/layer.js"/>
    <!-- md5.js -->
    <link type="text/javascript" href="/js/md5.min.js"/>
    <!-- common.js -->
    <link type="text/javascript" href="/js/common.js"/>
    <!-- vue.js -->
    <link type="text/javascript" href="/js/vue.js"/>
    <style type="text/css">
        html,body{
            height:100%;
            width:100%;
        }
        body{
            background:url('/img/bg2.jpg') no-repeat;
            background-size:100% 100%;
        }
        #goodslist td{
            border-top:1px solid #39503f61;
        }
    </style>
</head>
<body>

<div class="panel panel-default" style="height:100%;background-color:rgba(222,222,222,0.8)">
    <div class="panel-heading">秒杀商品列表</div>
    <table class="table" id="goodslist">
        <tr><td>商品名称</td><td>商品图片</td><td>商品原价</td><td>秒杀价</td><td>库存数量</td><td>详情</td></tr>
        <tr v-for="goods in goodsList">
            <td >{{goods.goodsName}}</td>
            <td ><img src="{{goods.goodsImg}}" width="100" height="100" /></td>
            <td>{{goods.goodsPrice}}</td>
            <td>{{goods.miaoshaPrice}}</td>
            <td>{{goods.stockCount}}</td>
            <td><a href="'/goods_detail.htm?goodsId='+${goods.id}">详情</a></td>
        </tr>
    </table>
</div>
</body>
</html>

<script>
    // computed:{
    //     goodsList:[]
    // }

    /**这里使用thymeleaf实现不了页面静态化，当通过ajax向后端请求数据返回给前端时，此时页面保存到本地
     * （即：静态化），此时渲染页面时识别不出th标识，所以实现不了前后端分离（即：页面静态化），只能用页面缓存**/
    //以下代码没用处
    // $(function () {//$(function () {}执行时机：加载页面完成时执行
    //     getGoodsList();
    // })

    function render(detail){
        var vm=new Vue({
            el:'#goodslist',
            data:{
                goodslist:goodsList
            }
        });
    }

    function getGoodsList() {
        $.ajax({
            url: "/goods/to_list",
            type: "GET",
            data:{

            },
            success:function(data){
                layer.closeAll();
                if(data.code == 0){
                    layer.msg("成功");
                    render(data.data);
                }else{
                    layer.msg(data.msg);
                }
            },
            error:function(){
                layer.closeAll();
            }
        });
    }

</script>